<!--
 * @name: 
 * @version: 1.1.1
 * @Author: 刘大可
 * @Date: 2022-11-15 10:59:16
 * @LastEditors: 刘大可
 * @LastEditTime: 2023-10-10 10:40:39
-->
<template>
    <view class="cu-modal bottom-modal" :class="isAuth ?'show':''"  @click="hidden">
        <view class="cu-dialog padding" @click.stop="">
            <view class="row" v-if="logo&&name">
                <image
                    class="logo margin-right"
                    :src="logo"
                    mode="scaleToFill"
                />
                <view class="name">
                    {{name}}
                </view>
                    
            </view>
            <view class="tips row">
                正在获取您的头像，昵称
            </view>
            <view class="flex" style="width:100%;">
                <view class="avatar">
                    <view class="cuIcon-cameraadd" style="font-size:70rpx;"></view>
                    上传头像
                    <image class="avatar-img" :src="avatarUrl"></image>
                    <button class="avatar-btn" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
                    </button>
                </view>
            </view>

            <!-- <button id="agree-btn3" open-type="getUserInfo|agreePrivacyAuthorization" bindgetuserinfo="handleGetUserInfo" bindagreeprivacyauthorization="handleAgreePrivacyAuthorization">同意隐私协议并获取头像昵称信息</button> -->

            <view class="cu-form-group">
                <view class="title">昵称</view>
                <input class="nickname " type="nickname"  v-model="nickName" placeholder="请输入昵称" @bindblur="bindblur"/>
                </view>
                <!-- {{ nickName }} -->
                <view class="row">
                    <!-- <view class="auth sj" @click="Auth">
                        随机头像
                    </view> -->
                    <view class="auth" @click="Auth">
                        登录
                    </view>
                </view>
                  
              
              
            <!-- <input class="nickname margin-top-xs"  placeholder="请输入昵称" placeholder-class="input-placeholder" @input="" /> -->
        </view>
    </view>
</template>
<script>
import siteInfo from '@/siteinfo.js';
var app = getApp();
export default {
    data() {
        return {
            modalName:'bottomModal',
            avatarUrl:"",
            nickName:"",
            logo:"",
            name:""
        }
    },
    props: {
        isAuth :{
            type: [Boolean],
            default () {
                return false;
            }
        },
    },
   async created(options) {


        let res=await  this.request('School/index',{
            openid: uni.getStorageSync('openid') ? uni.getStorageSync('openid') :
            'nologinuser' ,
            // lon: wx.getStorageSync('city').location.lng,
            // lat: wx.getStorageSync('city').location.lat,
        })
        uni.setStorageSync('schoolList', res.data.data.list);
                // uni.setStorageSync('sys', res.data.data.sys);

            


        let sys = uni.getStorageSync('schoolList').filter(item=>
            item.s_id == uni.getStorageSync('schoolId')
        )
        if (sys.length==0) {
            sys = uni.getStorageSync('schoolList')
        }
        console.log(sys);
        this.logo = sys[0].logo
        this.name = sys[0].s_name
        console.log(sys);
    },
    methods: {
        handleGetUserInfo(e){
            console.log(e);
        }, 
        handleAgreePrivacyAuthorization (e){
            console.log(e);
        },
        onChooseAvatar(e) {
            console.log(e);
            console.log(e.detail.avatarUrl);
            uni.uploadFile({
                url: siteInfo.url + 'Base/upload',
                filePath: e.detail.avatarUrl,
                formData: {
                    'wxapp_id': siteInfo.uniacid
                },
                header: {
                    'content-type': 'application/x-www-form-urlencoded'
                },
                name: 'file',
                success: (result) => {
                    var data = JSON.parse(result.data);
                    if (data.status == 200) {
                        this.avatar = data.data;
                        this.avatarUrl = data.data;

                        uni.hideLoading();
                    } else {
                        uni.showToast({
                            title: data.msg,
                            icon: 'none'
                        })
                    }
                }
            });
        },
        hidden(){
            uni.$emit('loginCell', {
                
            })
        },
        bindblur(e){
            console.log(e);
        },
        Auth(){

            let sys=uni.getStorageSync('sys')
            // sys.is_force_getinfo=0
            if (sys.is_force_getinfo==1) {
                if (!this.avatarUrl) {
                    return this.tips.tips("头像不能为空")
                }
                if (!this.nickName) {
                    return this.tips.tips("昵称不能为空")
                }
            }
            uni.$emit('loginCell', {
                userInfo:{
                    avatarUrl: this.avatarUrl,
                    nickName: this.nickName
                }
            })
            // userInfo:
            // avatarUrl: "https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTLRu6WAf6yzMyOOjatQRq8jsWPD2fkmogUpYoA4wkg6zuia861ZfibjdkFKibkFdbtjlfCYQ6HIB5c4g/132"
            // city: ""
            // country: ""
            // gender: 0
            // language: "zh_CN"
            // nickName: "平安喜乐"
            // province: ""
        }
    },
}
</script>
<style lang="scss">
    @import "./main.scss";
</style>